<template>
  <div>
    <!-- 图片详情 -->
    <Header></Header>
    <van-sticky>
      <van-nav-bar
        title="图片详情"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
        right-text="返回顶部"
        @click-right="onClickright"
      />
    </van-sticky>

    <div class="main">
      <div class="main-hd">
        <p>{{ imageInfo.title }}</p>
        <div class="main-item">
          <span>{{ imageInfo.add_time | fromdata }}</span>
          <span>{{ imageInfo.click }}次浏览</span>
          <span>分类：{{ imageInfo.category }}</span>
        </div>
      </div>
      <div class="main-img">
        <van-image
          v-for="(item, i) in thumimage"
          :key="i"
          width="100px"
          height="100px"
          :src="item.src"
        />
        <p v-html="imageInfo.content"></p>
      </div>
    </div>
    <Comment></Comment>
  </div>
</template>

<script>
import { getthumimages, getimageInfo } from "../api";
import Header from "../components/header.vue";
import Comment from "../components/comment.vue";
export default {
  components: {
    Comment,
    Header,
  },
  data() {
    return {
      imageInfo: [],
      thumimage: [], //图文数据
    };
  },

  async created() {
    const { data: res1 } = await getimageInfo(this.$route.params.id);
    this.imageInfo = res1.message[0];
    console.log(this.imageInfo);
    const { data: res } = await getthumimages(this.$route.params.id);
    // console.log(res);
    this.thumimage = res.message;
    console.log(this.thumimage);
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    },
    onClickright() {
      //   console.log(1);
      window.scrollTo({
        top: 0,
        behavior: "smooth",
      });
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  padding: 10px 5px;

  .main-hd {
    color: #0088d1;
    font-size: 20px;
    font-weight: 700;
    padding-bottom: 10px;
    border-bottom: 1px solid #ccc;
    .main-item {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #999;
      padding-top: 5px;
      span {
        margin-right: 5px;
      }
    }
  }

  .main-img {
    .van-image {
      padding: 10px;
    }
    p {
      color: #666;
      margin-bottom: 40px;
    }
  }
}
</style>
